<template>
  <div class="left-menu-cent">
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <!-- :background-color="variables.menuBg"
      :text-color="variables.menuText"
      :active-text-color="variables.menuActiveText" -->
      <el-menu
        :show-timeout="200"
        :default-active="$route.path"
        :collapse="isCollapse"
        mode="vertical"
        :background-color="variables.menuBg"
      >
        <sidebar-item
          v-for="route in curSiderMenu[0].children"
          :key="route.path"
          :item="route"
          :base-path="route.path"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import variables from "@/styles/variables.scss";
import SidebarItem from "./SidebarItem";
import { mapGetters } from "vuex";

export default {
  components: { SidebarItem },
  data() {
    return {
      isFirst: 1,
      curSiderMenu: []
    };
  },
  watch: {
    $route: {
      handler: function(val) {
        this.initSiderMenu(val);
      },
      deep: true
    },
  },
  mounted() {
    const curRoute = this.$route;
    this.initSiderMenu(curRoute);
  },
  computed: {
    ...mapGetters(["sidebar", "moduleKey", "permission_routers"]),
    variables() {
      return variables;
    },
    isCollapse() {
      return !this.sidebar.opened;
    }
  },
  methods: {
    initSiderMenu(val) {
      const matchRouteName = val.matched[0].name;
      const tgIndex = this.permission_routers.findIndex(item => item.name === matchRouteName);
      this.curSiderMenu = [ this.permission_routers[tgIndex] ];
    }
  }
};
</script>
<style lang="scss" scoped>
.header-describ {
  float: left;
  height: 20px !important;
  width: 120px;
  font-size: 3px;
}
.hamburger-container {
  float: right;
}
.el-header {
  height: 20px !important;
  border: 1px;
  background: #f4f4f5;
}
.el-main {
  padding: 0px !important;
}
.el-scrollbar {
  height: 100%;
}
/deep/ .el-menu-item .el-tooltip {
  padding: 0 2px 0 5px !important;
}
</style>
<style lang="scss">
div#app .sidebar-container ul.el-menu {
  background: #f4f6f8 !important;
  color: #4e5157 !important;
  font-size: 12px;
  font-weight: 600;
}

div#app .sidebar-container .el-menu-item.is-active {
  color: #0098ff !important;
  background-color: rgba(0, 152, 255, 0.08) !important;
  border-left: 3px solid #0098ff;
}
div#app .sidebar-container .el-menu-item.is-active span {
  color: #0098ff;
}
div#app .sidebar-container .el-menu-item:hover {
  background-color: rgba(0, 152, 255, 0.08) !important;
}
// div#app .sidebar-container .submenu-title-noDropdown.is-active:hover,
// div#app .sidebar-container .el-submenu__title.is-active:hover {
//   color: #0098ff;
//   background-color: #29a7e1 !important;
// }

// div#app .sidebar-container .submenu-title-noDropdown:hover,
// div#app .sidebar-container .el-submenu__title:hover {
//   background-color: #000 !important;
// }

div#app .el-menu-item,
div#app .el-submenu__title {
  background: #f4f6f8 !important;
  color: #4e5157 !important;
  border-left: 3px solid transparent;
}
div#app .sidebar-container .nest-menu .el-submenu > .el-submenu__title,
div#app .sidebar-container .el-submenu .el-menu-item {
  color: #4e5157 !important;
  background: #f4f6f8 !important;
}
div#app .sidebar-container .nest-menu .el-submenu > .el-submenu__title:hover,
div#app .sidebar-container .el-submenu .el-menu-item:hover {
  background-color: #f4f6f8 !important;
}

// div#app .sidebar-container .el-submenu .el-menu-item.is-active {
//   background-color: #29a7e1 !important;
// }
// div#app .sidebar-container .el-submenu .el-menu-item.is-active:hover {
//   background-color: #29a7e1 !important;
// }
.sidebar-container .el-submenu .el-menu-item span,
.sidebar-container .el-submenu__title span,
.sidebar-container .el-menu-item span {
  font-size: 14px;
}
.sidebar-container .svg-icon {
  width: 1.5em !important;
  height: 1.5em !important;
  vertical-align: -0.45em !important;
}
div#app .sidebar-container a {
  display: block;
}
.sidebar-container .el-menu-item,
.sidebar-container .el-submenu__title {
  height: 42px;
  line-height: 42px;
}
</style>